﻿using Volo.Abp.DependencyInjection;
using YAPACS.BusinessObjects.Exams;
using YAPACS.Workflows;

namespace YAPACS.RisServer.Workflows.Report;

public class GetEApply : WorkflowBase, IGetEApply, ITransientDependency
{
    protected override async Task<WorkflowOutput> InvokeCoreAsync(WorkflowInput input)
    {
        var workflowOutput = new WorkflowOutput
        {
            Success = true,
            ViewTitle = "电子申请单",
            ViewWidth = "50%"
        };
        const string key = "Exam";
        workflowOutput.View = await Extensions.GetResourceStringAsync("Resources.Report.e-apply-view.json");
        if (input.ContainsKey(key) && input.GetValueOrDefault(key) is Exam exam)
        {
            //获取检查的患者的信息
            workflowOutput.Data = new
            {
                exam.IsEmergency,
                exam.IsAppointment,
                exam.Patient?.Name,
                exam.Age,
                PatientSex = (int?)exam.Patient?.Sex,
                exam.Patient?.BirthDate,
                exam.Patient?.PhoneNumber,
                exam.Patient?.PhoneNumber2,
                exam.Patient?.IdCardNumber,
                exam.Patient?.MedicalInsuranceNumber,
                EthnicGroup = exam.Patient?.EthnicGroup?.Name,
                Profession = exam.Profession?.Name,
                exam.Height,
                exam.Weight,
                exam.Patient?.Address,
                exam.OutPatientNumber,
                exam.PhysicalExamNumber,
                exam.InPatientNumber,
                exam.BedNumber,
                exam.InPatientArea,
                exam.WardNumber,
                ApplyDepartment = exam.ApplyDepartment?.Name,
                ApplyDoctor = exam.ApplyDoctor?.Name,
                exam.ClinicalDiagnosis,
                exam.MedicalHistory,
                exam.AllergyHistory,
                exam.ChiefComplaint,
                ExamItems = exam.ExamItemsText
            };
        }
        return workflowOutput;
    }
}
